package org.lost.base;

import java.util.Objects;

public class OverrideHashCode {
    
    String name;
    
    int    age;
    
    @Override
    public boolean equals(Object o) {
        if (o == this) {
            return true;
        }
        if (!(o instanceof OverrideHashCode)) {
            return false;
        }
        OverrideHashCode user = (OverrideHashCode)o;
        return user.name.equals(name) && user.age == age;
        /*
         * 基于JDK1.7实现 
         */
        //                return user.age == age && Objects.equals(name , user.name);
    }
    
    @Override
    public int hashCode() {
        //《Effective Java》书中给出的一种算法，基于 17 和 31 散列码思想的实现，如下：
        int result = 17;
        result = 31 * result + name.hashCode();
        result = 31 * result + age;
        return result;
        /*
         * 基于JDK1.7实现 
         */
        //        return Objects.hash(name,age);
    }
}
